package com.luxoft.scoremanager.server.model.dao;

import com.luxoft.scoremanager.server.model.web.Component;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import java.io.Serializable;


@Entity
@Table
public class ComponentValuesDaoModel implements Serializable {
    private static final long serialVersionUID = -5170875020617735666L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "my_entity_seq_gen")
    @SequenceGenerator(name = "my_entity_seq_gen", sequenceName = "CVD_SEQ")
    @Column(name = "component_Values_id")
    private Integer id;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "component_ID")
    private ComponentDaoModel componentDaoModel;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "score_Package_ID")
    private ScorePackageDaoModel scorePackageDaoModel;

    @Column
    private String existsValue;

    @Column
    private String finalValue;

    @Override
    public String toString() {
        return "ComponentValuesDao{" +
                "id=" + id +
                ", componentDao=" + componentDaoModel +
                ", scorePackageDao=" + scorePackageDaoModel +
                ", existsValue='" + existsValue + '\'' +
                ", finalValue='" + finalValue + '\'' +
                '}';
    }

    public ComponentValuesDaoModel() {
    }

    public ComponentValuesDaoModel(Component component) {
        this.setFinalValue(component.getFinalValue());
        this.setExistsValue(component.getExistsValue());
        this.setComponentDao(new ComponentDaoModel(component.getId(), component.getLabel(), component.getStaticData()));
        this.setId(component.getComponentValuesId());
    }

    public ComponentValuesDaoModel(String existsValue, String finalValue) {
        this.existsValue = existsValue;
        this.finalValue = finalValue;
    }

    public ComponentValuesDaoModel(Integer id, String existsValue, String finalValue) {
        this.existsValue = existsValue;
        this.finalValue = finalValue;
    }

    public ComponentValuesDaoModel(String existsValue, String finalValue, ComponentDaoModel componentDaoModel, ScorePackageDaoModel scorePackageDaoModel) {
        this.existsValue = existsValue;
        this.finalValue = finalValue;
        this.scorePackageDaoModel = scorePackageDaoModel;
        this.componentDaoModel = componentDaoModel;
    }

    @Override
    public boolean equals(Object o) {

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ComponentValuesDaoModel that = (ComponentValuesDaoModel) o;

        if (!id.equals(that.id)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

    public Integer getId() {

        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public ComponentDaoModel getComponentDao() {
        return componentDaoModel;
    }

    public void setComponentDao(ComponentDaoModel componentDaoModel) {
        this.componentDaoModel = componentDaoModel;
    }

    public ScorePackageDaoModel getScorePackageDao() {
        return scorePackageDaoModel;
    }

    public void setScorePackageDao(ScorePackageDaoModel scorePackageDaoModel) {
        this.scorePackageDaoModel = scorePackageDaoModel;
    }

    public String getExistsValue() {
        return existsValue;
    }

    public void setExistsValue(String existsValue) {
        this.existsValue = existsValue;
    }

    public String getFinalValue() {
        return finalValue;
    }

    public void setFinalValue(String finalValue) {
        this.finalValue = finalValue;
    }


}
